
import { Button } from "antd"
import { useEffect } from "react";
import {create} from "zustand"
import axios from "axios"

const useStore = create(set=>{
    return {
        count:0,
        increment:()=>set(state=>({count:state.count+1})),
        commList:[],
        getComment:async()=>{
            const response = await axios.get("http://localhost:3004/list")

            console.log(response);
            set(state=>({commList:response.data}))
        }
    }
})


const ZustandPage = () => {
    const {count,increment,commList,getComment} = useStore()

    useEffect(()=>{
        getComment();
    },[])
    return (
        <>
        <p className="mb-5">zustand需要先 pnpm i zustand --save 安装</p>
       
        <Button onClick={increment}> {count}</Button>

        <div>
            获取到数据：<br></br>
            {JSON.stringify(commList)}  
        </div>
        </>
    )
}
export default ZustandPage;